import { CenoOptionsRegistry } from "../types/options";
import { CenoRequestInit } from "../types/request";

export const supportsAbortController = typeof globalThis.AbortController === 'function'
export const supportsResponseStreams = typeof globalThis.ReadableStream === 'function'
export const supportsFormData = typeof globalThis.FormData === 'function'


export const requestMethods = ["get", "post", "put", "delete", "patch", "head"] as const;

export const responseTypes = {
	json: 'application/json',
	text: 'text/*',
	formData: 'multipart/form-data',
	arrayBuffer: '*/*',
	blob: '*/*',
} as const;

export const maxSafeTimeout = 2_147_483_647;

export const usualFormBoundarySize = new TextEncoder().encode('------WebKitFormBoundaryaxpyiPgbbPti10Rw').length;

export const cenoOptionKeys: CenoOptionsRegistry = {
    json: true,
    parseJson: true,
    stringifyJson: true,
    searchParams: true,
    prefixUrl: true,
    retry: true,
    timeout: true,
    interceptors: true,
    throwHttpErrors: true,
    onDownloadProgress: true,
    onUploadProgress: true,
    fetch: true,
}

export const requestOptionsRegistry: CenoRequestInit = {
    body: true,
    cache: true,
    credentials: true,
    headers: true,
    integrity: true,
    keepalive: true,
    method: true,
    mode: true,
    priority: true,
    redirect: true,
    referrer: true,
    referrerPolicy: true,
    signal: true,
    window: true,
    dispatcher: true,
    duplex: true,
}